// 创建birds.js
var express = require('express')
var contenttypeApi = express.Router()// 创建一个路由实例


// 中间件功能
contenttypeApi.use(function timeLog(req, res, next) {
  console.log('Time: ', new Date().toLocaleString())
  next()
})
// 访问/postApi
contenttypeApi.post('/contenttypeTest', function (req, res) {
  console.log('zdy-----headers：------>' + JSON.stringify(req.headers))
  console.log('zdy-----path------>' + JSON.stringify(req.path))
  console.log('zdy-----baseUrl------>' + JSON.stringify(req.baseUrl))
  let requestPath = ''
  if (req.baseUrl != undefined && req.baseUrl != '' && req.baseUrl != null && req.baseUrl.trim().length > 0) {
    requestPath = req.baseUrl
  } else if (req.path != undefined && req.path != '' && req.path != null && req.path.trim().length > 0) {
    requestPath = req.path
  }
  let requestUrl = ''
  if ('http' === req.protocol) {
    requestUrl = 'http://' + req.hostname + requestPath
  } else {
    requestUrl = 'https://' + req.hostname + requestPath
  }
  console.log('zdy-----requestUrl------>' + requestUrl)
  console.log('zdy-----body------>' + JSON.stringify(req.body))

  let responseMsg = '请求：' + requestUrl + '成功'
  res.json({
    header: req.headers,
    body: req.body,
    method: req.method,
    url: req.baseUrl,
    msg: responseMsg
  })
})


module.exports = contenttypeApi